<%@page import="cn.kgc.news.util.PageSupport"%>
<%@page import="cn.kgc.news.pojo.Detail"%>
<%@page import="java.util.List"%>
<%@page import="cn.kgc.news.service.impl.DetailServiceImpl"%>
<%@page import="cn.kgc.news.service.DetailService"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>无标题文档</title> <script>
		function addNews() {
			location.href = "newsDetailCreateSimple.jsp";
		}
		function page_nav(frm,num) {
			frm.pageIndex.value = num;
			frm.submit();
		}
		function jump_to(frm,pageNo) {
			var regexp = /^[1-9]\d*$/;
			var totalPageCount = document.getElementById("totalPageCount").value;
			if(!regexp.test(pageNo)){
				alert("请输入数字！！！");
				return false;
			}else if((pageNo - totalPageCount) > 0){
				alert("兄弟,你过分了啊,总共就"+totalPageCount+"页");
				return false;
			}else{
				page_nav(frm,pageNo);
			}
		}
	</script>
	<link type="text/css" rel="stylesheet"
		href="<%=request.getContextPath()%>/css/common.css" />
	<style type="text/css">
<!--
-->
</style>
</head>

<body>
	${msg}
	<!--主体-->
	<div class="main-content-right">
		<!--即时新闻-->
		<div class="main-text-box">
			<div class="main-text-box-tbg">
				<div class="main-text-box-bbg">
					<form name="searchForm" id="searchForm"
						action="newsDetailList.jsp" method="post">
						<div>
							新闻分类： <select name="categoryId">
								<option value="0">全部</option>

								<option value='1'>国内</option>

								<option value='2'>国际</option>

								<option value='3'>娱乐</option>

								<option value='4'>军事</option>

								<option value='5'>财经</option>

								<option value='6'>天气</option>

							</select> 新闻标题<input type="text" name="title" id="title" value='' />
							<button type="submit" class="page-btn">GO</button>
							<button type="button" onclick="addNews();" class="page-btn">增加</button>
							<input type="hidden" name="pageIndex" value="2" /> <input
								type="hidden" name="pageSize" value="10" /> <input type="hidden"
								name="totalPageCount" value="2" />
						</div>
					</form>
					<table cellpadding="1" cellspacing="1" class="admin-list">
						<thead>
							<tr class="admin-list-head">
								<th>新闻标题</th>
								<th>作者</th>
								<th>时间</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<%
								DetailService service = new DetailServiceImpl();
								//创建分页工具类
								PageSupport pageSupport = new PageSupport();
								//设置当前页数 2
								String currentPage = request.getParameter("pageIndex");
								if(currentPage == null){
									//用户第一次访问
									currentPage = "1";
								}
								pageSupport.setCurrentPage(Integer.parseInt(currentPage));
								//设置页容量
								pageSupport.setPageSize(2);
								//设置总条数
								pageSupport.setTotalCount(service.getTotalCount());
								List<Detail> details = 
										service.getPage(pageSupport.getCurrentPage(), 
												pageSupport.getPageSize());
								request.setAttribute("news", details);
							%>
							<input type="hidden" id="totalPageCount" value="<%=pageSupport.getTotalCountPage()%>"/>
							<c:forEach var="news" items="${news }" varStatus="i">
							<tr <c:if test="${i.count%2==0 }" >class="admin-list-td-h2"</c:if> >
								<td><a href='<c:url value="newsDetailView.jsp?id=${news.id }"/>'><c:out value="${news.title }" escapeXml="true"/></a></td>
								<td>${news.auth }</td>
								<td><fmt:formatDate value="${news.createDate }" pattern="yyyy/MM/dd HH:mm:ss" /> </td>
								<td><a href='adminNewsCreate.jsp?id=${news.id }'>修改</a> <a
									href="javascript:if(confirm('确认是否删除此新闻？')) location='adminNewsDel.jsp?id=${news.id }'">删除</a>
								</td>
							</tr>
							</c:forEach>
							
						</tbody>
					</table>
					<div class="page-bar">
						<ul class="page-num-ul clearfix">
							<li>共 <%=pageSupport.getTotalCount() %> 条记录&nbsp;&nbsp; <%=pageSupport.getCurrentPage() %> / <%=pageSupport.getTotalCountPage() %>页</li>
							<%if(pageSupport.getCurrentPage() != 1){ %>
							<a href="javaScript:page_nav(document.forms[0],1)">首页</a>
							<a href="javaScript:page_nav(document.forms[0],<%=pageSupport.getCurrentPage()-1 %>)">上一页</a>
							<%
							}
							if (pageSupport.getCurrentPage() != pageSupport.getTotalCountPage()){
							%>
							<a href="javaScript:page_nav(document.forms[0],<%=pageSupport.getCurrentPage()+1 %>)">下一页</a>
							<a href="javaScript:page_nav(document.forms[0],<%=pageSupport.getTotalCountPage()%>)">最后一页</a>&nbsp;&nbsp;
							<%
							}
							%>
						</ul>
						<span class="page-go-form"><label>跳转至</label> <input
							type="text" name="inputPage" id="inputPage" class="page-key" />页
							<button type="button" class="page-btn"
								onClick='jump_to(document.forms[0],document.getElementById("inputPage").value)'>GO</button>
						</span>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
</html>